<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form ref="filterForm" :model="filterForm" :inline="true" label-position="left" label-width="100px">
        <el-form-item label="时间" prop="publishTime">
          <el-date-picker 
            v-model="filterForm.publishTime"
            value-format="yyyy-MM-dd"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
            <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
              搜索
            </el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      >
      <el-table-column
        type="selection"
        width="55"
      />
      <el-table-column label="日期" >
        <template slot-scope="{row}">
          <span>{{ row.cycle }}</span>
        </template>
      </el-table-column>
      <el-table-column label="文章">
        <template slot-scope="{row}">
          <span>{{ row.documentationNum }}</span>
        </template>
      </el-table-column>
      <el-table-column label="问题" >
        <template slot-scope="{row}">
          <span>{{ row.questionNum }}</span>
        </template>
      </el-table-column>
      <el-table-column label="渠道">
        <template slot-scope="{row}">
          <span>{{ row.originateNum }}</span>
        </template>
      </el-table-column>
      <el-table-column label="成员数量" >
        <template slot-scope="{row}">
          <span>{{ row.employeeNum }}</span>
        </template>
      </el-table-column>
      <el-table-column label="渠道" >
        <template slot-scope="{row}">
          <span>{{ row.domainNum }}</span>
        </template>
      </el-table-column>
      <el-table-column label="客户">
        <template slot-scope="{row}">
          <span>{{ row.customerNum }}</span>
        </template>
      </el-table-column>
      <el-table-column label="机构">
        <template slot-scope="{row}">
          <span>{{ row.companyNum }}</span>
        </template>
      </el-table-column>
      <el-table-column label="流量">
        <template slot-scope="{row}">
          <span>{{ row.accessNum }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最后更新" width="200">
        <template slot-scope="{row}">
          <span>{{ row.updatedAt }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="filterForm.start" :limit.sync="filterForm.perpage" @pagination="getList" />
  </div>
</template>

<script>
import { getBoardList, } from '@/api/analysis/board'
import waves from '@/directive/waves' // waves directive
import { } from '@/utils'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination

export default {
  name: 'ComplexTable',
  components: { Pagination },
  directives: { waves },
  filters: {
  },
  data() {
    return {
      listLoading: false,
      tableKey: 0,
      filterForm: {
        start: 1,
        perpage: 10,
        remove:1,
        owne:0,
        keyword: '',
        sort: '+id'
      },
      list: null,
      total: 0
    }
  },
  created() {
    this.getList()
  },
  watch:{
  },
  methods: {
    sortChange(data) {
      const { prop, order } = data
      if (prop === 'id') {
        this.sortByID(order)
      }
    },
    sortByID(order) {
      if (order === 'ascending') {
        this.filterForm.sort = '+id'
      } else {
        this.filterForm.sort = '-id'
      }
      this.handleFilter()
    },
    getList() {
      this.listLoading = true
      getBoardList(this.filterForm).then(response => {
        this.list = response.data.list
        this.total = response.data.total

        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 1.5 * 1000)
      })
    },
    handleFilter() {
      this.filterForm.start = 1
      this.getList()
    }
  }
}
</script>
